<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div id="app">
        
    </div>
    <script>
        let data = {
            msg: 'Hello'
        }
        let vm = {}
        //数据劫持
        Object.defineProperty(vm, 'msg',{
            enumerable:true,
            configurable:true,
            get(){
                console.log('get',data.msg)
                return data.msg
            },
            set(newValue){
                console.log('set',newValue)
                if(newValue === data.msg){
                    return
                }
                data.msg = newValue
                document.querySelector('#app').textContent = data.msg
            }
        })
        vm.msg = 'Hello World'
        console.log(vm.msg)
    </script>
</body>
</html>